import Vue from 'vue'
import VueRouter from 'vue-router'
// import { getLocalStorage } from '@/utils/localStorage'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login/index.vue'),
    meta: {
      title: '礼租租车 -- 服务商管理后台登录',
      isPublic: true
    }
  },
  {
    path: '/',
    name: 'layout',
    redirect: '/order/manage',
    component: () => import(/* webpackChunkName: "manage" */ '../views/layout/index.vue'),
    children: [
      {
        path: '/order/manage',
        name: 'orderManage',
        component: () => import(/* webpackChunkName: "manage" */ '../views/orderManage/index.vue'),
        meta: {
          title: '礼租租车 -- 服务商订单管理',
          icon: 'icon-gongdan',
          roles: ['管理员', '客服'],
          breadcrumbName: ['订单列表']
        },
        title: '订单列表',
        hidden: false
      },
      {
        path: '/user/manage',
        name: 'userManage',
        component: () => import(/* webpackChunkName: "manage" */ '../views/userManage/index.vue'),
        meta: {
          title: '礼租租车 -- 服务商员工管理',
          icon: 'icon-huiyuan',
          roles: ['管理员', '客服'],
          breadcrumbName: ['员工列表']
        },
        title: '员工列表',
        hidden: false
      }
    ]
  }
]

const createRouter = () => new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

const resetRouter = function () {
  const newRouter = createRouter()
  console.log(newRouter)
}

export {
  routes,
  resetRouter
}

const router = createRouter()

export default router
